package com.hu.zhcc.shiro.controller;


import com.hu.zhcc.shiro.entity.tj.*;
import com.hu.zhcc.shiro.service.TJ_TMemberService;
import com.hu.zhcc.shiro.service.Tj_TMentalityResultService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 心理测评结果 前端控制器
 * </p>
 *
 * @author tj
 * @since 2021-06-30
 */
@RestController
@RequestMapping("/tjtMentalityResult")
public class TjTMentalityResultController {
    @Autowired
    private Tj_TMentalityResultService tjTMentalityResultService;//心理测评结果
    @Autowired
    private TJ_TMemberService tjTMemberService;//会员表
    @Autowired
    @GetMapping("/queryAllResult")
    public List<TMentalityResult> queryAlResult(){
        System.out.println(tjTMentalityResultService.queryAllResult());
     return  tjTMentalityResultService.queryAllResult();
    }
    //根据会员身份证查询
    @GetMapping("/{idCard}")
    public VipdaTj queryByidsCard(@PathVariable("idCard") String idCard){
        TMember tMember = tjTMemberService.queryByIsCard(idCard);
        VipdaTj vipdaTj=new VipdaTj();
        vipdaTj.setMember(tMember);
        return vipdaTj;
    }
    //插入数据
    @PostMapping("/{sum}/{sum2}/{sum3}/{id}")
    public int addXlcp(@PathVariable("sum") Integer sum,@PathVariable("sum2") Integer sum2,@PathVariable("sum3")Integer sum3,@PathVariable("id") Integer id){
        TQuestionnaireAnswer tQuestionnaireAnswer=new TQuestionnaireAnswer();
        tQuestionnaireAnswer.settMemberId(id);
        TMentalityResult tMentalityResult = new TMentalityResult();
        if(sum>=10){
            tMentalityResult.settOcd(0);
        }else {
            tMentalityResult.settOcd(1);
        }
        if (sum2>=10) {
            tMentalityResult.settAnxiety(0);
        }else {
            tMentalityResult.settAnxiety(1);
        }
        if(sum3>=10){
            tMentalityResult.settTerror(0);
        }else {
            tMentalityResult.settTerror(1);
        }
        tMentalityResult.settMemberId(id);
        Date today = new Date(System.currentTimeMillis());
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String date = simpleDateFormat.format(today);
        tMentalityResult.setCreatetime(date);
        int i = tjTMentalityResultService.addXlcp(tMentalityResult);
        return i;
    }

    //根据会员编号和时间删除
    @DeleteMapping("/{id}/{createtime}")
    public int delXlcp(@PathVariable("id")Integer id,@PathVariable("createtime")String createtime){
      return   tjTMentalityResultService.delXlcp(id,createtime);
    }


}

